import React from 'react'
import Layout from '../core/Layout'
import { Form, Input, Button, message } from 'antd';
import { Link } from 'react-router-dom'
import axios from 'axios'
import { isAuth } from '../../helper/auth'
import { API } from '../../config'

export default function createCategory() {
	const {
		token,
		user: { _id }
	} = isAuth()
	const onFinish = async value => {
		await axios.post(`${API}/category/create/${_id}`, value, {
			headers: {
				Authorization: `Bearer ${token}`
			}
		}).then(res=>{
			message.success(`${res.data.name}分类模块添加成功`)
		}).catch(err=>{
			message.error('添加失败')
		})
	}
	return (
		<>
			<Layout title="添加分类">
				<Form onFinish={onFinish}>
					<Form.Item label="分类名称" name="name">
        		<Input />
					</Form.Item>
					<Form.Item>
        		<Button type="primary" htmlType="submit">
        		  添加分类
        		</Button>
      	</Form.Item>
				</Form>
				<Button>
					<Link to="/admin/dashboard">返回 Dashboard</Link>
				</Button>
			</Layout>
		</>
	)
}
